﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Benefit.ViewModel.Month
{
    /// <summary>
    /// 月度阶段总结
    /// </summary>
    public class StageMonthSummary
    {
        /// <summary>
        /// 左侧菜单显示信息
        /// </summary>
        public LeftMenuInfos LeftMenuInfos { get; set; }

        /// <summary>
        /// 查询用户
        /// </summary>
        public Models.Sys.Operator Operator { get; set; }

        public string QueryYear { get; set; }

        public string QueryMonth { get; set; }

        public string Pdate { get; set; }

        public string DateQuery { get; set; }

        public string LastDate { get; set; }

        public List<Models.View.OperatorMonthTick> WinTicks { get; set; }

        public List<Models.View.OperatorMonthTick> LostTicks { get; set; }

        public List<Models.View.OperatorMonthProductInfo> ProductInfos { get; set; }

        public Models.View.OperatorMonthMoney OperatorMonthMoney { get; set; }

        public List<Models.Month.AccountMonthMoney> AccountMonthMoney { get; set; }

        public string JS { get; set; }

        #region 定义一些使用到的接口
        private Interface.Sys.ITradeHistory ITradeHistory = null;
        private Interface.Sys.IOperator IOperator = null;
        private Interface.View.IOperatorMonthTick IOperatorMonthTick = null;
        private Interface.View.IOperatorMonthProductInfo IOperatorMonthProductInfo = null;
        private Interface.View.IOperatorMonthMoney IOperatorMonthMoney = null;
        private Interface.Month.IAccountMonthMoney IAccountMonthMoney = null;
        private Interface.View.IOperatorDayChange IOperatorDayChange = null;
        private Interface.View.IOperatorMonthSum IOperatorMonthSum = null;
        #endregion



        public StageMonthSummary(int operatorId, int queryDate, DB.DBManager db)
        {
            this.QueryYear = queryDate.ToString().Substring(0, 4);
            this.QueryMonth = queryDate.ToString().Substring(4, 2);
            this.DateQuery = queryDate.ToString();
            this.Operator = IOperator.GetModel(operatorId);
            this.LastDate = ITradeHistory.GetLastTradeHistoryDateString();
            this.WinTicks = IOperatorMonthTick.GetOperatorMonthWinOrLostTicks(operatorId, Convert.ToInt32(this.QueryMonth), Convert.ToInt32(this.QueryYear), true);
            this.LostTicks = IOperatorMonthTick.GetOperatorMonthWinOrLostTicks(operatorId, Convert.ToInt32(this.QueryMonth), Convert.ToInt32(this.QueryYear), false);
            this.ProductInfos = IOperatorMonthProductInfo.GetSortedOperatorMonthProductInfo(Convert.ToInt32(this.QueryMonth), Convert.ToInt32(this.QueryYear), operatorId);
            this.OperatorMonthMoney = IOperatorMonthMoney.GetOperatorMonthMoney(Convert.ToInt32(this.QueryMonth), Convert.ToInt32(this.QueryYear), operatorId);
            this.AccountMonthMoney = IAccountMonthMoney.GetAccountAndAllChange(operatorId, Convert.ToInt32(this.QueryMonth), Convert.ToInt32(this.QueryYear));
            List<Models.View.OperatorDayChange> operatorDayChanges = IOperatorDayChange.GetOperatorDayChange(operatorId, Convert.ToInt32(this.QueryMonth), Convert.ToInt32(this.QueryYear));
            this.JS += Benefit.Tools.ChartAtManager.ChartManager.GetOperatorMonthYieldString(operatorDayChanges);
            Models.View.OperatorMonthSum operatorMonthSum = IOperatorMonthSum.GetOperatorMonthSum(operatorId, Convert.ToInt32(this.QueryMonth), Convert.ToInt32(this.QueryYear));
            this.JS += Benefit.Tools.ChartAtManager.ChartManager.MonthDiffBar(operatorMonthSum);
        }


        private void InitInterface(DB.DBManager db)
        {
            #region 初始化接口
            ITradeHistory = new Service.Sys.ServiceTradeHistory(db);
            IOperator = new Service.Sys.ServiceOperator(db);
            IOperatorMonthTick = new Service.View.ServiceOperatorMonthTick(db);
            IOperatorMonthProductInfo = new Service.View.ServiceOperatorMonthProductInfo(db);
            IOperatorMonthMoney = new Service.View.ServiceOperatorMonthMoney(db);
            IAccountMonthMoney = new Service.Month.ServiceAccountMonthMoney(db);
            IOperatorDayChange = new Service.View.ServiceOperatorDayChange(db);
            IOperatorMonthSum = new Service.View.ServiceOperatorMonthSum(db);
            #endregion
        }
        /// <summary>
        /// 释放接口
        /// </summary>
        private void DisposeInterface()
        {
            #region 释放接口
            ITradeHistory = null;
            IOperator = null;
            IOperatorMonthTick = null;
            IOperatorMonthProductInfo = null;
            IOperatorMonthMoney = null;
            IAccountMonthMoney = null;
            IOperatorDayChange = null;
            IOperatorMonthSum = null;
            #endregion
        }
    }
}
